package severlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LoginOutServlet", value = "/LoginOutServlet")
public class LoginOutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 用户注销
        //取得登录的用户名
        HttpSession session = request.getSession();
        //销毁session
        session.invalidate();
//        response.sendRedirect(request.getContextPath()+"/index.jsp");
//        是为了解决相对路径的问题，可返回站点的根路径。
        response.sendRedirect("index.jsp");
    }
}
